package com.alibaba.citrus.cr.mn.order.center.facade.function.convert;

import com.alibaba.citrus.cr.common.util.DateUtils;
import com.epoch.app.crforecastsales.model.dto.SearchForecastOrderRequest;
import com.epoch.app.mnordercenter.model.dto.ForecastOrderLineRepoQueryReq;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @author zhoubc
 * @date 2023/5/31 14:28
 */
public class ForecastOrderLineRepoQueryReqToSearchForecastOrderRequestConvertor {

    public static SearchForecastOrderRequest convert(ForecastOrderLineRepoQueryReq forecastOrderLineRepoQueryReq) {
        SearchForecastOrderRequest searchForecastOrderRequest = new SearchForecastOrderRequest();
        searchForecastOrderRequest.setId(forecastOrderLineRepoQueryReq.getId());
        searchForecastOrderRequest.setMainOrderBizId(forecastOrderLineRepoQueryReq.getFrontOrderBizId());
        searchForecastOrderRequest.setMainId(forecastOrderLineRepoQueryReq.getFrontOrderId());
        //searchForecastOrderRequest.setGoodsIds(Lists.newArrayList());
        //searchForecastOrderRequest.setOutIds(Lists.newArrayList());
        searchForecastOrderRequest.setGoodsCodeLike(forecastOrderLineRepoQueryReq.getScItemCodeLike());
        searchForecastOrderRequest.setProductCode(forecastOrderLineRepoQueryReq.getScItemTitleLike());
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getProductGroupCodeList())){
            searchForecastOrderRequest.setProductGroupCodeList(forecastOrderLineRepoQueryReq.getProductGroupCodeList());
        }
        searchForecastOrderRequest.setBusinessType(forecastOrderLineRepoQueryReq.getBusinessType());
        searchForecastOrderRequest.setCustomerCode(forecastOrderLineRepoQueryReq.getCustomerCode());
        //searchForecastOrderRequest.setCustomerCodeList(Lists.newArrayList());
        searchForecastOrderRequest.setReceiveAddressCode(forecastOrderLineRepoQueryReq.getReceiveAddressCode());
        //searchForecastOrderRequest.setReceiveAddressCodeList(Lists.newArrayList());
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getSalesOrganizations())){
            searchForecastOrderRequest.setOrganizationCodeList(forecastOrderLineRepoQueryReq.getSalesOrganizations());
        }
        searchForecastOrderRequest.setSaleChannelCodeList(forecastOrderLineRepoQueryReq.getSaleChannels());
        searchForecastOrderRequest.setDepartmentCodeList(forecastOrderLineRepoQueryReq.getSalesDepartments());
        searchForecastOrderRequest.setChannelCodeList(forecastOrderLineRepoQueryReq.getBizChannelList());
        //searchForecastOrderRequest.setMainStatusList(Lists.newArrayList());
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getSubStatusList())){
            searchForecastOrderRequest.setDetailStatusList(forecastOrderLineRepoQueryReq.getSubStatusList());
        }
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getForecastOrderTypeList())){
            searchForecastOrderRequest.setOrderTypeList(forecastOrderLineRepoQueryReq.getForecastOrderTypeList());
        }
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getRejectReasonList())){
            searchForecastOrderRequest.setRefuseReasonList(forecastOrderLineRepoQueryReq.getRejectReasonList());
        }
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getCreateReasonList())){
            searchForecastOrderRequest.setDocReasonList(forecastOrderLineRepoQueryReq.getCreateReasonList());
        }
        searchForecastOrderRequest.setTransportModeCodeList(forecastOrderLineRepoQueryReq.getDeliveryMethod()!=null? Lists.newArrayList(forecastOrderLineRepoQueryReq.getDeliveryMethod()):null);
        searchForecastOrderRequest.setCustomerReferenceNo(forecastOrderLineRepoQueryReq.getCustomerReferenceNo());
        //forecastOrderLineRepoQueryReq.getCustomerPurchaseDateList()
        if (CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getCustomerExpectDateList())) {
            searchForecastOrderRequest.setCustomerExpectStartDate(forecastOrderLineRepoQueryReq.getCustomerExpectDateList().get(0) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getCustomerExpectDateList().get(0)));
            searchForecastOrderRequest.setCustomerExpectEndDate(forecastOrderLineRepoQueryReq.getCustomerExpectDateList().get(1) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getCustomerExpectDateList().get(1)));
        }
        if (CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getGmtCreateList())) {
            searchForecastOrderRequest.setGmtStartCreate(forecastOrderLineRepoQueryReq.getGmtCreateList().get(0) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getGmtCreateList().get(0)));
            searchForecastOrderRequest.setGmtEndCreate(forecastOrderLineRepoQueryReq.getGmtCreateList().get(1) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getGmtCreateList().get(1)));
        }
        if (CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getGmtUpdateList())) {
            searchForecastOrderRequest.setUpdateStartTime(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(0) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(0)));
            searchForecastOrderRequest.setUpdateEndTime(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(1) == null ? null : DateUtils.string2Date(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(1)));
//            searchForecastOrderRequest.setUpdateStartTime(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(0) == null ? null : com.alibaba.citrus.cr.common.util.DateUtils.convertToMillisecondStr(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(0)));
//            searchForecastOrderRequest.setUpdateEndTime(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(1) == null ? null : com.alibaba.citrus.cr.common.util.DateUtils.convertToMillisecondStr(forecastOrderLineRepoQueryReq.getGmtUpdateList().get(1)));
        }
        //searchForecastOrderRequest.setValidStartDate(new Date());
        //searchForecastOrderRequest.setValidEndDate(new Date());

        searchForecastOrderRequest.setCreatorId(forecastOrderLineRepoQueryReq.getCreatorId());
        searchForecastOrderRequest.setCreatorIdList(forecastOrderLineRepoQueryReq.getCreatorIdList());
        searchForecastOrderRequest.setCreatorName(forecastOrderLineRepoQueryReq.getCreator());
        searchForecastOrderRequest.setModifierId(forecastOrderLineRepoQueryReq.getUpdatorId());
        searchForecastOrderRequest.setModifierName(forecastOrderLineRepoQueryReq.getUpdator());
        //searchForecastOrderRequest.setWareHouseCode("");
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getShippingWarehouseList())){
            searchForecastOrderRequest.setWareHouseCodes(forecastOrderLineRepoQueryReq.getShippingWarehouseList());
        }
        if(CollectionUtils.isNotEmpty(forecastOrderLineRepoQueryReq.getSalesOrganizationOutCodes())){
            searchForecastOrderRequest.setSalesOrganizationOutCodes(forecastOrderLineRepoQueryReq.getSalesOrganizationOutCodes());
        }

//        searchForecastOrderRequest.setContact("");
//        searchForecastOrderRequest.setContactPhone("");
//        searchForecastOrderRequest.setSalesmanCode("");
//        searchForecastOrderRequest.setSourceOrderNo("");
//        searchForecastOrderRequest.setSourceOrderNoList(Lists.newArrayList());
//        searchForecastOrderRequest.setDeliveryFactoryCode("");
//        searchForecastOrderRequest.setStockCode("");
//        searchForecastOrderRequest.setShipToPartyCodeList(Lists.newArrayList());
//        searchForecastOrderRequest.setSoldToPartyCodeList(Lists.newArrayList());

        searchForecastOrderRequest.setStart(forecastOrderLineRepoQueryReq.getStart());
        searchForecastOrderRequest.setLimit(forecastOrderLineRepoQueryReq.getLimit());
        searchForecastOrderRequest.setDir(forecastOrderLineRepoQueryReq.getDir());
        searchForecastOrderRequest.setAsc(forecastOrderLineRepoQueryReq.getAsc());
        searchForecastOrderRequest.setSize(forecastOrderLineRepoQueryReq.getSize());
        searchForecastOrderRequest.setPage(forecastOrderLineRepoQueryReq.getPage());

        return searchForecastOrderRequest;
    }
}
